package com.example.springboot.controller;

import com.example.springboot.domain.ResourceCategory;
import com.example.springboot.domain.ResponseResult;
import com.example.springboot.service.ResourceCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ResourceCategory")
public class ResourceCategoryController {

    @Autowired
    private ResourceCategoryService resourceCategoryService;

    @RequestMapping("/findAllResourceCategory")
    public ResponseResult findAllResourceCategory(){
        List<ResourceCategory> allResourceCategory = resourceCategoryService.findAllResourceCategory();

        return  new ResponseResult(true,200,"查询所有分类信息成功",allResourceCategory);

    }

    @RequestMapping("/addOrUpdateResourceCategory")
    public ResponseResult addOrUpdateResourceCategory(@RequestBody ResourceCategory resourceCategory) {
        if(resourceCategory.getId()==null) {
            resourceCategoryService.addResource(resourceCategory);
            return new ResponseResult(true,200,"添加资源信息成功",null);
        } else {
            resourceCategoryService.updateResource(resourceCategory);
            return new ResponseResult(true,200,"修改资源信息成功",null);
        }
    }

    @RequestMapping("/deleteResourceCategory")
    public ResponseResult deleteResourceCategory(@RequestParam int id) {
        resourceCategoryService.deleteResourceCategory(id);
        return new ResponseResult(true,200,"删除资源资源信息成功",null);
    }


}
